<template>
  <div class="photoinfo-container">
    <!-- 标题区域 -->
    <h3 class="title">{{ photoinfo.title }}</h3>
    <p class="info">
      <span>发布时间：{{ photoinfo.add_time | dateFormat }}</span>
      <span>点击：{{ photoinfo.click }}次</span>
    </p>
    <hr />

    <!-- 缩略图区域 -->
    <div class="thumb-img-list">
      <vue-preview :slides="thumblist" @close="handleClose"></vue-preview>
    </div>

    <!-- 内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>

    <!-- 评论子组件 -->
    <comment :newsid="photoinfo.id"></comment>
  </div>
</template>

<script>
import comment from "../sub-components/Comment.vue";
export default {
  data() {
    return {
      photoinfo: {},
      thumblist: [], // 缩略图数组
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbImg();
  },
  methods: {
    async getPhotoInfo() {
      // 当调用一个异步的方法，同时，这个异步方法的返回值是 Promise 对象的时候，才可以使用 await 和 async
      const { data } = await this.$http.get("/api/getimageInfo/" + this.id);
      if (data.status === 0) {
        this.photoinfo = data.message[0];
      }
    },
    async getThumbImg() {
      // 获取图片的缩略图数据
      const { data } = await this.$http.get("/api/getthumimages/" + this.id);
      if (data.status === 0) {
        //  为 每一张图片设置 宽和高
        data.message.forEach((item) => {
          item.msrc = item.src;
          item.alt = "图片加载失败";
          //   item.title = "";
          item.w = 1200;
          item.h = 900;
        });

        this.thumblist = data.message;
      }
    },
    handleClose() {
      console.log("close event");
    },
  },
  props: ["id"],
  components: {
    comment,
  },
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .info {
    display: flex;
    justify-content: space-between;
    color: #26a2ff;
  }

  .thumb-img-list {
    img {
    }
  }
  .content {
    font-size: 15px;
    line-height: 30px;
  }
}
</style>